package com.example.uCenter.user.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.uCenter.common.Code;
import com.example.uCenter.common.Paging;
import com.example.uCenter.common.Result;
import com.example.uCenter.user.entity.Fans;
import com.example.uCenter.user.mapper.FansMapper;
import com.example.uCenter.user.service.IFansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hhl
 * @since 2022-08-29 08:38:53
 */
@Transactional //事务
@Service
public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IFansService {

    /**
     * 分页查询
     * hhl
     *
     * @param current 当前页
     * @param size    每页大小
     * @return 类型Result 查询成功返回20091返回单表中所有当前页的结果集、总页数、总记录数、当前页、每页大小、提示语句
     */
    @Override
    public Result findPaging(Integer current, Integer size) {
        IPage<Fans> page = new Page<>(current, size);
        getBaseMapper().selectPage(page, null);
        long pages = page.getPages();
        List<Fans> records = page.getRecords();
        System.out.println("测试点一");
        long total = page.getTotal();
        Result result = new Result();
        Paging paging = new Paging(pages, records, total, current, size);
        result.setCode(Code.GET_ALL_OK);
        result.setData(paging);
        result.setMsg("共" + page.getPages() + "页、" + page.getTotal() + "条记录，第" + current + "页查询成功，还剩下" + (page.getPages() - current) + "页");
        System.out.println("测试点二");
        return result;
    }
}
